<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--{include file='comm/header.tpl'}-->
    <!--{if isset($user_array)}-->
    <title>用户修改</title>
    <!--{else}-->
    <title>用户新增</title>
    <!--{/if}-->
<!--{include file='comm/comm_pic.tpl'}-->
<style>
	li{
		width:164px;
		height:24px;
		line-height:24px;
		text-align:left;
		display:block;
		float:left;
	}
</style>
</head>
<body>
	<div style="width:100%">
		
		<div class="items clearfix">
			
			<h2 style="" class="tal">
				正在操作：
				<!--{if isset($user_array)}-->
			    	用户修改
			    <!--{else}-->
                    用户新增
			    <!--{/if}-->
			</h2>
			
			<div class="items2">

                <div class="select-box">
                    <div id="select_1"<!--{if $operFlg == 2}--> class="selected"<!--{/if}-->>
                        用户信息
                    </div>

                    <div id="select_2"<!--{if $operFlg == 3}--> class="selected"<!--{/if}-->>
                        用户角色
                    </div>
                </div>

                <div>
                    <form id="userForm" onsubmit="return false;">

                        <div id="form_1"<!--{if $operFlg == 3}--> style="display: none;" <!--{/if}-->>
                            <table>
                                <tr>
                                    <td width="150" class="tar">用户名：</td>
                                    <td  width="*">
                                        <!--{if isset($user_array)}-->
                                            <!--{$user_array.userID}-->
                                            <input type="hidden" name="userID" value="<!--{$user_array.userID}-->" />
                                        <!--{else}-->
                                            <input type="text" name="userID" style="width:200px;" />
                                        <!--{/if}-->
                                        <input type="hidden" name="uuid" value="<!--{$user_array.uuid|default:''}-->" />
                                        <span class="red">*</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="tar">用户姓名：</td>
                                    <td>
                                        <input type="text" name="trueName" style="width:200px;" value="<!--{$user_array.trueName|default:''}-->" />
                                        <span class="red">*</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="tar">密码：</td>
                                    <td>
                                        <input type="password" name="userPwd" style="width:200px;" />
                                        <span class="red">*</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="tar">密码确认：</td>
                                    <td>
                                        <input type="password" name="repeatPwd" style="width:200px;" />
                                        <span class="red">*</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="tar">email：</td>
                                    <td>
                                        <input type="text" name="email" style="width:200px;" value="<!--{$user_array.email|default:''}-->" />
                                        <span class="red">*</span>
                                    </td>
                                </tr>

                                <!--{if isset($mall_array)}-->
                                <tr>
                                    <td class="tar">所属门店：</td>
                                    <td>
                                        <select name="mallID" style="width:140px;">
                                            <option value="0">请选择</option>
                                            <!--{foreach from=$mall_array item=mall}-->
                                                <option value="<!--{$mall.mallID}-->"<!--{if isset($user_array) && $user_array.extend_1 == $mall.mallID}--> selected="selected"<!--{/if}-->><!--{$mall.mallName}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </td>
                                </tr>
                                <!--{/if}-->

                                <!--{if isset($store_array)}-->
                                    <tr>
                                        <td class="tar">所属仓库：</td>
                                        <td>
                                            <!--{foreach from=$store_array item=store}-->
                                                <input type="checkbox" value="<!--{$store.storeID}-->" name="store"<!--{if $store.checked}-->checked="checked"<!--{/if}--> /> <!--{$store.storeName}-->
                                            <!--{/foreach}-->
                                        </td>
                                    </tr>
                                <!--{/if}-->

                                <tr>
                                    <td class="tar">使用标志：</td>
                                    <td width="*">
                                        <!--{if !isset($user_array)}-->
                                            <input type="radio" name="useFlg" value="1" checked="checked">&nbsp;启用
                                            <input type="radio" name="useFlg" value="0">&nbsp;禁用
                                        <!--{else}-->
                                            <input type="radio" name="useFlg" value="1" <!--{if $user_array.useFlg == 1}--> checked="checked" <!--{/if}-->>&nbsp;启用
                                            <input type="radio" name="useFlg" value="0" <!--{if $user_array.useFlg == 0}--> checked="checked" <!--{/if}-->>&nbsp;禁用
                                        <!--{/if}-->
                                    </td>
                                </tr>
                            </table>
                        </div>

                        <div id="form_2"<!--{if $operFlg == 2}--> style="display: none;" <!--{/if}-->>
                            <!--{foreach from=$role_group_array item=group}-->
                                <div style="margin-left:50px;margin-bottom:2px;margin-top:8px;font-weight:bolder;">
                                    <!--{$group.roleGroupName}-->
                                </div>
                                <ul style="width:656px;padding-left:50px;margin-bottom:5px;">
                                    <!--{foreach from=$group.role_list item=role_list}-->
                                        <li>
                                            <input type="checkbox" name="user_role" value="<!--{$role_list.roleID}-->"<!--{if $role_list.checked}--> checked="checked"<!--{/if}-->>&nbsp;<!--{$role_list.roleName}-->
                                        </li>
                                    <!--{/foreach}-->
                                </ul>
                                <div style="clear:both;"></div>
                            <!--{/foreach}-->
                        </div>

                    </form>
                </div>

			</div>
			
		</div>
		
		<div class="bottom_fixbox">
	        <div class="rectbox tac">
	            <input type="button" class="btn" onclick="user.check();" value="保存" />&nbsp;&nbsp;&nbsp;
	            <input type="button" class="btn" onclick="E.closeWindows();" value="关闭" />
	        </div>
	    </div>
		
	</div>

<script type="text/javascript">

    var user = {

        userID: "<!--{$user_array.userID|default:''}-->",

        dt: "",

        check: function() {

            this.dt = E.getFormValues("userForm");
            var error_log = "";

            if (E.isEmpty(this.dt.userID)) {
                error_log += "用户名不能为空<br>";
            }
            if (E.isEmpty(this.dt.trueName)) {
                error_log += "用户姓名不能为空<br>";
            }
            if (!this.userID || (this.userID && !E.isEmpty(this.dt.userPwd))) {
                if (!E.isPwd(this.dt.userPwd)) {
                    error_log += "密码必须是6-30位字符，可使用字母、数字或符号的组合<br>";
                }
                if (this.dt.userPwd != this.dt.repeatPwd) {
                    error_log += "两次输入的密码不一致<br>";
                }
            }
            if (!E.isEmail(this.dt.email)) {
                error_log += "邮件不能为空或格式错误<br>";
            }
            if (this.dt.user_role.length == 0) {
                error_log += "请选择用户角色<br>";
            }
            if (error_log != "") {
                E.alert(error_log);
            } else {
                E.confirm("您确认要保存用户信息吗？", "user.save");
            }

        },

        save: function() {
            E.loadding.open("正在保存用户信息，请稍候...");
            E.ajax_post({
                url: "/invokingAjax-backend/user/userList.ajax?operFlg=2",
                data: this.dt,
                call: "user.result"
            })
        },

        result: function( o ) {

            E.loadding.close();
            if (o.code == 200) {
                E.opener("user.load");
                if (this.userID) {
                    E.alert(o.message, 2, "E.closeWindows");
                } else {
                    E.alert(o.message, 2, "E.refresh");
                }
            } else {
                E.alert(o.message);
            }

        }

    };

    $(window).ready(function() {

        $("div[id^=select_]").click(function() {

            var id = $(this).attr("id").replace("select_", "");
            $("div[id^=select_]").removeClass("selected").eq($(this).index()).addClass("selected");
            $("div[id^=form_]").hide().eq($(this).index()).show();

        });

    });

</script>

</body>
</html>